package net.dreamlu.qa.model;

import java.util.Date;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

/**
 * 标签Model
 * @author lcm
 */
public class Tags extends Model<Tags> {
	private static final long serialVersionUID = 1L;
	public static final Tags dao = new Tags();
	
	// 添加标签的统一处理
	public void addTag(Tags tag){
		tag.set("create_time", new Date()).set("update_time", new Date()).save();
	}
	// 更新标签统一处理
	public void updateTags(Tags tag){
		tag.set("update_time", new Date()).update();
	}
	
	// 获取模糊查询的 数目
	public Integer getLikeCount(String like){
		Long count = Db.queryLong("select count(1) from tags where tag_name like '%"+ like +"%' and del_status = 0");
		return count == null ? 0 : count.intValue();
	}
	
	// 获取模糊查询的 page
	public Page<Tags> getLinkPage(int pageNum, int pageSize, String like){
		return Tags.dao.paginate(pageNum, pageSize, "select * ", "from tags where tag_name like '%"+ like +"%' and del_status = 0 order by id desc");
	}
}